# 测试类
from Page.Page import Page
from Page.Page1 import Page1
from Page.Page2 import Page2
from selenium import webdriver
import time,pytest,yaml,logging
from datetime import datetime
def open_yaml():
    with open('D:\PYCHARM2024\day9-7\yuekao_zzd_0812\Page\login.yaml','r',encoding='utf-8') as e:
        return yaml.safe_load(e)
@pytest.fixture(scope='function')
def driver():
    driver=webdriver.Edge()
    driver.maximize_window()
    driver.implicitly_wait(10)
    yield driver
    driver.quit()
@pytest.mark.parametrize('data',open_yaml())
def test_01_baidu_login_search(driver,data):
    logging.info('用例1')
    try:
        po=Page(driver)
        po.open_url('https://www.baidu.com/')
        po.search1()
        time.sleep(3)
        # 1.点击登录按钮
        po.login()
        # 2.输入用户名
        po.user(data['username'])
        # 3.输入密码
        po.passw(data['password'])
        time.sleep(3)
        # 4.点击协议
        po.xieyi()
        # 5.点击登录按钮
        po.login1()
        time.sleep(3)
        if data['city'] == "F1":
            po.home()
            time.sleep(3)
            # 6.搜索框搜索
            po.search()
            time.sleep(5)
            print(data['dy'])
        else:
            print(data['dy'])
    except Exception as e:
        datime=datetime.now().strftime('%Y%m%d-%H%M%S')
        driver.save_screenshot(f'{datime}1.png')
        print(e)
def test_02_baidu_login_tieba(driver):
    logging.info('用例2')
    try:
        po=Page1(driver)
        po.luoji_02_login_tieba()
    except Exception as e:
        datime=datetime.now().strftime('%Y%m%d-%H%M%S')
        driver.save_screenshot(f'{datime}2.png')
        print(e)
def test_03_baidu_login_gj_search(driver):
    logging.info('用例3')
    try:
        po=Page2(driver)
        po.luoji_03_login_search()
    except Exception as e:
        datime=datetime.now().strftime('%Y%m%d-%H%M%S')
        driver.save_screenshot(f'{datime}3.png')
        print(e)
